#pragma once
#include "HashTableOpean.h"

namespace ForcibleBugMaker
{
	// using OpenHash::HashBucket;
	
	template<class K,class V>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const std::pair<K, V>& kv)
			{
				return kv.first;
			}
		};

	public:
		typedef typename OpenHash::HashBucket<K, std::pair<const K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename OpenHash::HashBucket<K, std::pair<const K, V>, MapKeyOfT>::ConstIterator const_iterator;

		iterator begin()
		{
			return _tables.Begin();
		}

		iterator end()
		{
			return _tables.End();
		}

		const_iterator begin() const
		{
			return _tables.Begin();
		}

		const_iterator end() const
		{
			return _tables.End();
		}

		V& operator[](const K& key)
		{
			iterator ret = _tables.Insert(std::make_pair(key, V()));
			return ret->second;
		}

		void insert(const std::pair<const K, V>& kv)
		{
			_tables.Insert(kv);
		}

		void erase(const K& key)
		{
			_tables.Erase(key);
		}

		void clear()
		{
			_tables.Clear();
		}

		bool find(const K& key)
		{
			return bool(_tables.Find(key));
		}

		size_t size()
		{
			return _tables.Size();
		}

		bool empty()
		{
			return _tables.Empty();
		}

	private:
		OpenHash::HashBucket<K, std::pair<const K, V>, MapKeyOfT> _tables;
	};

}